//
//  BaseTableViewController.swift
//  Swift_WeiBo
//
//  Created by dajie on 15/8/21.
//  Copyright (c) 2015年 dajie. All rights reserved.
//

import UIKit
import Alamofire
class BaseTableViewController: UITableViewController, LoginNomalViewDelegate {

    weak var loginNormalView : LoginNomalView?
    var isLogin : Bool!
    
//  MARK: - 视图初始化设置
    override func loadView()
    {
        isLogin = shareUseraccount == nil ? false : true
        isLogin == true ? super.loadView() : setUpEmptyLoginView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let leftButton = UIButton(frame: CGRectMake(0, 0, 60, 44))
        leftButton.setTitle("登录", forState: UIControlState.Normal)
        leftButton.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        leftButton .addTarget(self, action: "loginNormalViewLogin", forControlEvents: UIControlEvents.TouchUpInside)
        let leftBarbutton = UIBarButtonItem(customView: leftButton as UIButton)
        navigationItem.leftBarButtonItem = leftBarbutton
        
        let rightButton = UIButton(frame: CGRectMake(0, 0, 60, 44))
        rightButton.setTitle("注册", forState: UIControlState.Normal)
        rightButton.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        rightButton .addTarget(self, action: "loginNormalViewregist", forControlEvents: UIControlEvents.TouchUpInside)
        let rightBarbutton = UIBarButtonItem(customView: rightButton as UIButton)
        navigationItem.rightBarButtonItem = rightBarbutton;
    }
    
//MARK: - 创建没有登录的时候的界面
    func setUpEmptyLoginView()
    {
        loginNormalView = NSBundle.mainBundle().loadNibNamed("LoginNomalView", owner: nil, options: nil).last as? LoginNomalView
        loginNormalView?.loginDalegate = self  //  设置代理
        self.view = loginNormalView
    }
    
//MARK: - 导航条上登陆、注册按钮点击
    func loginNormalViewLogin()
    {
        loginNormalViewLogin(loginView: nil, button: nil)
    }
    func loginNormalViewregist()
    {
        loginNormalViewregist(loginView: nil, button: nil)
    }
    func loginNormalViewLogin(loginView loginView: LoginNomalView?, button: UIButton?)
    {
        let sb = UIStoryboard(name: "OAuthLoginVIew", bundle: nil)
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        presentViewController(nav, animated: true, completion: nil)
        print("点击登录")
    }
    func loginNormalViewregist(loginView loginView: LoginNomalView?, button: UIButton?)
    {
         print("点击注册")
    }
}
